<template>
  <div class="m-app-home">
    <recommend :store="store" @refress="handlerHomeInfo"></recommend>
    <GoodsStatus :goods="store.goodsDynamic" :order="store.orderDynamic"></GoodsStatus>
    <SalesStatistics :statistics="store.salesStatistics" :ranking="store.salesRanking"></SalesStatistics>
  </div>
</template>

<script>
  import Recommend from './recommend'
  import GoodsStatus from './goodsStatus'
  import SalesStatistics from './salesStatistics'

  // 首页的店家信息
  import { apiHomeStoreInfo } from '../../common/api'

  export default {
    components: {
      Recommend,
      GoodsStatus,
      SalesStatistics
    },
    data() {
      return {
        store: {}
      }
    },
    created() {
      this.handlerHomeInfo()
    },
    methods: {
      /**
       * 查询首页信息
       */
      handlerHomeInfo() {
        apiHomeStoreInfo(this.$store.getters.token).then((data) => {
          // 将商品的信息保存到全局作用域中
          this.store = data

          // 将店铺信息保存到sessionStorage中
          sessionStorage.setItem('storeInfo', JSON.stringify(this.store))
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>